package dao;

import models.Album;
import models.Photo;

import java.util.*;

/**
 * Created by VLAD on 19.08.2014.
 */
public class AlbumDao implements IAlbumDao{

    private Map<Integer, Album> recourses = new HashMap();

    @Override
    public void addAlbum(Album album) {
        recourses.put(album.getId(), album);
    }

    @Override
    public List getAllAlbums() {
        List<Album> toReturn = new LinkedList<Album>();

        Iterator<Album> iter = recourses.values().iterator();
        while (iter.hasNext())
        {
            Album tmp = iter.next();
            if(tmp.getPhotos().size() != 0) {
                toReturn.add(tmp);
            }
            else {
                delAlbum(tmp);
            }
        }

        return toReturn;
    }

    @Override
    public Album getAlbumById(int id) {
        return recourses.get(id);
    }

    @Override
    public void delAlbum(Album album) {
        recourses.remove(album.getId());

    }

    @Override
    public int getSize() {
        return recourses.size();
    }
}
